package org.List.Iterator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.ListIterator;

/**
 * @author rain-falling-cold-s
 **/
public class IteratorDemo {
    public static void main(String[] args) {
        var myPets = new ArrayList<String>();
        myPets.add("猫");
        myPets.add("狗");
        myPets.add("鸟");
        myPets.add("猪");
        for (var pet : myPets) {
            System.out.print(pet + " ");
        }
        System.out.println();
        var BigPets = new ArrayList<>(Arrays.asList("老虎", "狮子", "大象"));
        myPets.add(BigPets.get(0));
        myPets.add(BigPets.get(1));
        BigPets.add("鲸鱼");
        System.out.println(myPets.contains("大象"));
        var listIterator = myPets.listIterator();
        while (listIterator.hasNext()) {
            String pet = listIterator.next();
            System.out.print(pet + " ");
        }
        System.out.println();
    }
}
